Add mapopolis.com mapconverter format as an internally parsed XCSV style.
authoralexmot <alexmot@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 12 Aug 2003 14:57:38 +0000 (14:57 +0000)
committeralexmot <alexmot@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 12 Aug 2003 14:57:38 +0000 (14:57 +0000)
gpsbabel/README
gpsbabel/README.mapconverter [new file with mode: 0644]
gpsbabel/csv_util.c
gpsbabel/csv_util.h
gpsbabel/defs.h
gpsbabel/internal_styles.c
gpsbabel/style/custom.style
gpsbabel/style/mapconverter.style [new file with mode: 0644]
gpsbabel/util.c
gpsbabel/xcsv.c

index 2f6cbccc691374837ebb5fee335885985192e742..87baeab3e81e1908851b8f26557e68dee9f0f026 100644 (file)
@@ -385,6 +385,12 @@ THE FORMATS
        to text so it can be pulled into a spreadsheet or manipulated
        with text processing tools.
 
+    mapconverter
+
+       Mapconverter is a format this is read by Mapopolis.com's mapconverter
+       application.  Full details of it's usage are available in the file
+       README.mapconverter.
+
 DATA FILTERS
 
        GPSBabel supports data filtering.  Data filters are invoked from
diff --git a/gpsbabel/README.mapconverter b/gpsbabel/README.mapconverter
new file mode 100644 (file)
index 0000000..2713baf
--- /dev/null
@@ -0,0 +1,35 @@
+Mapconverter is an application used to create userland maps and map data for 
+Mapopolis.com's Mapopolis program.  The mapconverter format is essentially
+waypoint data prepared in a format that the mapconverter application will
+accept.
+
+The steps for using GPSBabel and Mapconverter go something like this:
+
+Step 1: Create a mapconverter file using gpsbabel.
+       ./gpsbabel -i geo -f geocaching.loc -o mapconverter -F foo.txt
+       
+Step 2: Launch mapconverter.exe and choose foo.txt as your input file.
+       Click the begin button to have mapconverter process foo.txt.
+
+If all goes successfully, you should have a file called "foo.pdb" ready
+for syncing with your PDA.  Put it wherever Mapopolis thinks it should be
+on your PDA.
+
+NOTES:
+
+o GPSBabel encodes "foo.txt" to have mapconverter use the output filename 
+  of "foo.pdb".  Similarly, if you tell GPSBabel to write output as
+  "bananagps.txt", mapconverter output will be "bananagps.pdb".
+
+o The PocketPC version of Mapopolis doesn't notice files with the ".pdb"
+  extension.  To make this work, change the extension to ".mlp" when
+  copying the mapconverter output to your PocketPC PDA.
+
+o Mapconverter only works with Mapopolis version 3.x.  Mapopolis version
+  4 will refuse to load mapconverter maps.  There is no known work-around
+  for this at the time of this writing.
+
+o Mapconverter is no longer available from the Mapopolis website.  If you
+  need a copy of mapconverter, ask on your local GPS Software discussion
+  forum and I'm sure someone will have it.  As far as I know, It was never 
+  actually acknowledged/supported by Mapopolis to begin with.
index 77ebc90df23e0c65fc1d20b7627aa3870c87689a..7d94878226254953db14543d3d276e2586699df9 100644 (file)
@@ -819,8 +819,18 @@ xcsv_data_write(void)
     
     /* output prologue lines, if any. */
     QUEUE_FOR_EACH(&xcsv_file.prologue, elem, tmp) {
-        ogp = (ogue_t *) elem;
-        fprintf (xcsv_file.xcsvfp, "%s%s", ogp->val, xcsv_file.record_delimiter);
+       char *ol;
+       ogp = (ogue_t *) elem;
+
+       ol = strsub(ogp->val, "__FILE__", xcsv_file.fname);
+
+       if (ol) {
+               fprintf(xcsv_file.xcsvfp, "%s", ol);
+               free(ol);
+       } else {
+               fprintf(xcsv_file.xcsvfp, "%s", ogp->val);
+       }
+       fprintf(xcsv_file.xcsvfp, "%s", xcsv_file.record_delimiter);
     }
 
     switch (global_opts.objective ) {
index 872173d793830d409bba74cd0ebe6a8a07912ab5..7338fa8bac9fe9ffe134337c5da86db40dbda0be 100644 (file)
@@ -114,6 +114,7 @@ typedef struct {
     int ofield_ct;             /* actual # of ofields */
     
     FILE * xcsvfp;             /* ptr to current *open* data file */
+    char * fname;                /* ptr to filename of above. */
 
     char * description;                /* Description for help text */
     char * extension;          /* preferred filename extension (for wrappers)*/
index cc445c91c45f8e4d6c903616900c30f58d93e98d..0914ab619456e309c05b946edbe93acaa416d942 100644 (file)
@@ -342,7 +342,7 @@ void debug_mem_close();
 
 int case_ignore_strcmp(const char *s1, const char *s2);
 
-
+char *strsub(char *s, char *search, char *replace);
 void rtrim(char *s);
 signed int get_tz_offset(void);
 const char *get_cache_icon(const waypoint *waypointp);
index 1751a6d21f07513f7c26227d6fb56980042e8304..7777360b28e553942b36f6af032423cfb26334b2 100644 (file)
@@ -69,7 +69,7 @@ static char custom[] =
 "#\n"
 "# HEADER STUFF:\n"
 "#\n"
-"PROLOGUE      Prologue Line 1\n"
+"PROLOGUE      Prologue Line 1 __FILE__\n"
 "PROLOGUE      Prologue Line 2\n"
 
 "#\n"
@@ -243,6 +243,43 @@ static char gpsman[] =
 
 "# gpsman.c likes mkshort len = 8, whitespace = 0.\n"
 ;
+static char mapconverter[] = 
+"# Format: Mapopolis.com Mapconverter\n"
+"# Author: Gary Paulson\n"
+"#   Date: 01/13/2003\n"
+"# Requires unsupported mapconverter.exe from mapopolis.com.\n"
+"#\n"
+"# Modifications by Alex Mottram documented 6/30/2003\n"
+"# Change %-40.40s on description output to %-.40s to stop padding.\n"
+"# Add QUOTE as badchars, remove COMMA.\n"
+"# Removed Mapconverter.exe's README information from style file.\n"
+"# Changed OFIELD to IFIELD in case you ever want to read one of these things.\n"
+"#\n"
+"#\n"
+"DESCRIPTION           Mapopolis.com Mapconverter CSV\n"
+"EXTENSION             txt\n"
+
+"# FILE LAYOUT DEFINITIIONS:\n"
+
+"FIELD_DELIMITER   COMMASPACE\n"
+"RECORD_DELIMITER  NEWLINE\n"
+"BADCHARS          \",\n"
+
+"# Map Info Record (header):\n"
+"PROLOGUE M, \"Geocaches\", \"GPSBabel\", Geocaches, __FILE__\n"
+"#\n"
+
+"#\n"
+"# INDIVIDUAL DATA FIELDS, IN ORDER OF APPEARANCE:\n"
+"#\n"
+"# L Records:\n"
+"IFIELD  CONSTANT, \"L\", \"%s\"               # [L]ANDMARK\n"
+"IFIELD  CONSTANT, \"Geocaches\", \"%s\"     # Category for Landmark Searches\n"
+"IFIELD  DESCRIPTION, \"\", \"%-.40s\"       # Name\n"
+"IFIELD  CONSTANT, \"1\", \"%s\"               # View at Zoom Level 1 (1-4)\n"
+"IFIELD  LON_DECIMAL, \"\", \"%08.5f\"       # Longitude\n"
+"IFIELD  LAT_DECIMAL, \"\", \"%08.5f\"       # Latitude\n"
+;
 static char mxf[] = 
 "# gpsbabel XCSV style file\n"
 "#\n"
@@ -481,4 +518,4 @@ static char xmapwpt[] =
 "IFIELD        DESCRIPTION, \"\", \"%-.78s\"\n"
 ;
 #include "defs.h"
-style_vecs_t style_list[] = {{ "xmapwpt", xmapwpt } , { "xmap", xmap } , { "s_and_t", s_and_t } , { "ozi", ozi } , { "nima", nima } , { "mxf", mxf } , { "gpsman", gpsman } , { "gpsdrive", gpsdrive } , { "fugawi", fugawi } , { "dna", dna } , { "custom", custom } , { "csv", csv } , { "arc", arc } ,  {0,0}};
+style_vecs_t style_list[] = {{ "xmapwpt", xmapwpt } , { "xmap", xmap } , { "s_and_t", s_and_t } , { "ozi", ozi } , { "nima", nima } , { "mxf", mxf } , { "mapconverter", mapconverter } , { "gpsman", gpsman } , { "gpsdrive", gpsdrive } , { "fugawi", fugawi } , { "dna", dna } , { "custom", custom } , { "csv", csv } , { "arc", arc } ,  {0,0}};
index 7a158b60582c674c8e81bdaf3b0c003dbeaf0d4f..1c871cb066270d7b5f57fcd016354cf55bb17523 100644 (file)
@@ -17,7 +17,7 @@ BADCHARS              COMMA
 #
 # HEADER STUFF:
 #
-PROLOGUE       Prologue Line 1
+PROLOGUE       Prologue Line 1 __FILE__
 PROLOGUE       Prologue Line 2
 
 #
diff --git a/gpsbabel/style/mapconverter.style b/gpsbabel/style/mapconverter.style
new file mode 100644 (file)
index 0000000..cf38b1f
--- /dev/null
@@ -0,0 +1,35 @@
+# Format: Mapopolis.com Mapconverter
+# Author: Gary Paulson
+#   Date: 01/13/2003
+# Requires unsupported mapconverter.exe from mapopolis.com.
+#
+# Modifications by Alex Mottram documented 6/30/2003
+# Change %-40.40s on description output to %-.40s to stop padding.
+# Add QUOTE as badchars, remove COMMA.
+# Removed Mapconverter.exe's README information from style file.
+# Changed OFIELD to IFIELD in case you ever want to read one of these things.
+#
+#
+DESCRIPTION            Mapopolis.com Mapconverter CSV
+EXTENSION              txt
+
+# FILE LAYOUT DEFINITIIONS:
+
+FIELD_DELIMITER   COMMASPACE
+RECORD_DELIMITER  NEWLINE
+BADCHARS          ",
+
+# Map Info Record (header):
+PROLOGUE M, "Geocaches", "GPSBabel", Geocaches, __FILE__
+#
+
+#
+# INDIVIDUAL DATA FIELDS, IN ORDER OF APPEARANCE:
+#
+# L Records:
+IFIELD  CONSTANT, "L", "%s"            # [L]ANDMARK
+IFIELD  CONSTANT, "Geocaches", "%s"     # Category for Landmark Searches
+IFIELD  DESCRIPTION, "", "%-.40s"       # Name
+IFIELD  CONSTANT, "1", "%s"            # View at Zoom Level 1 (1-4)
+IFIELD  LON_DECIMAL, "", "%08.5f"       # Longitude
+IFIELD  LAT_DECIMAL, "", "%08.5f"       # Latitude
index 5f68ec3c18c7d7a9012a797a085ff472955945d1..fb5f624e1b4e3e1ecf95fc22e76cd25bcfd4ff3f 100644 (file)
@@ -305,6 +305,7 @@ fatal(const char *fmt, ...)
        va_list ap;
        va_start(ap, fmt);
        vfprintf(stderr, fmt, ap);
+       va_end(ap);
        exit(1);
 }
 
@@ -314,6 +315,7 @@ warning(const char *fmt, ...)
        va_list ap;
        va_start(ap, fmt);
        vfprintf(stderr, fmt, ap);
+       va_end(ap);
 }
 
 /*
@@ -535,3 +537,37 @@ double degrees2ddmm(double deg_val) {
        deg = (signed int) deg_val;
        return (double) (deg * 100.0) + ((deg_val - deg) * 60.0);
 }
+
+/*
+ * replace a single occurrence of "search" in  "s" with "replace".
+ * Returns an allocated copy if substitution was made, otherwise returns NULL.
+ * Doesn't try to make an optimally sized dest buffer.
+ */
+char *
+strsub(char *s, char *search, char *replace)
+{
+       char *p;
+       int len = strlen(s);
+       int slen = strlen(search);
+       int rlen = strlen(replace);
+       char *d;
+
+       p = strstr(s, search);
+       if (!slen || !p) {
+               return NULL;
+       }
+       
+       d = xmalloc(len + rlen);
+
+       /* Copy first part */
+       len = p - s;
+       memcpy(d, s, len);
+       d[len] = 0;
+
+       /* Copy replacement */
+       strcat(d, replace);
+
+       /* Copy last part */
+       strcat(d, p + slen);
+       return d;
+}
index 259992577a26960285215bf25128105155c1e64e..b99d5af32ed08f9f088502969191637aa3375a34 100644 (file)
@@ -493,6 +493,7 @@ xcsv_wr_init(const char *fname, const char *args)
     }
 
     xcsv_file.xcsvfp = fopen(fname, "w");
+    xcsv_file.fname = (char *)fname;
 
     if (xcsv_file.xcsvfp == NULL)
         fatal(MYNAME ": Cannot open %s for writing\n", fname);